package com.hushao.aimi.repository;

import com.hushao.aimi.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @description: 角色
 * @author: 胡少
 * @create: 2018-06-04 00:38
 **/
public interface RoleRepository extends JpaRepository<Role,String>{
    /**
     * 根据用户查询其角色
     * @param userId
     * @return
     */
    @Query(value = "SELECT c.id,c.name,c.create_time,c.update_time,c.comment FROM aimi_store.user_role AS a JOIN aimi_store.aimi_user AS  b ON a.user_id=b.id JOIN aimi_store.`role` AS  c ON a.role_id=c.id WHERE b.id=?1",nativeQuery = true)
    List<Role> listRoleByUser(String userId);
}
